package mysql

import "gorm.io/gorm"

type Hospital struct {
	gorm.Model
	HospitalName    string `gorm:"type:varchar(20)" json:"hospitalName"`
	Introduction    string `gorm:"type:varchar(50)" json:"introduction"`
	HospitalAddress string `gorm:"type:varchar(255)" json:"hospitalAddress"`
}

func (h *Hospital) FindHospitals(page, pageSize int) (hospital []*Hospital, err error) {
	err = DB.Model(&h).Limit(pageSize).Offset((page - 1) * pageSize).Find(&hospital).Error
	if err != nil {
		return nil, err
	}
	return hospital, nil
}
func (h *Hospital) FindHospital(id int64) (*Hospital, error) {
	err := DB.Where("id=?", id).Find(&h).Error
	if err != nil {
		return nil, err
	}
	return h, nil
}
